package com.itqf.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * projectName: springframeworkgp8
 *
 * @author: 赵伟风
 * time: 2021/8/2 15:17
 * description:
 */

@Component("person")  // <bean id="person" class="com.itqf.pojo.person"
//默认: 单例 非延迟加载 : 初始化容器创建对象!
@Lazy //延迟加载
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
//<bean id="person" class="com.itqf.pojo.Person" lazy-init=true  scope = prototype
public class Person {

    @Value("${jdbc.user}")
    private String name;

//    @Autowired
//    @Qualifier("aotuo")

    @Resource(name = "aotuo") // == @Autowired + @Qualifier("aotuo")
    public Car car;



    public Person() {
        System.out.println("Person.Person");
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }


    @PostConstruct // == init方法
    public void init(){
        System.out.println("Person.init");
    }

    @PreDestroy  //== destroy
    public void destroy(){
        System.out.println("Person.destroy");
    }


}
